package com.zhj.edudemo.bean;

import com.baomidou.mybatisplus.annotation.*;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.hibernate.validator.constraints.Range;
import org.springframework.util.StringUtils;

import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.util.Date;

/**
 * @author zhj
 * @version 1.0
 * description:
 */
@Data
@NoArgsConstructor
public class Furn {
    @TableId(value = "m_id", type = IdType.ASSIGN_ID) // 雪花算法
    @JsonSerialize(using= ToStringSerializer.class)
    private Long id;
    @NotEmpty(message = "请输入家居名---")
    private String name;
    @NotEmpty(message = "请输入厂商名---")
    private String maker;
    @NotNull(message = "请输入数字---")
    @Range(min = 0, max = 1000, message = "价格区间:1-1000")
    private double price;
    @NotNull(message = "请输入数字---")
    @Range(min = 0, message = "销量不能小于0")
    private Integer sales;
    @NotNull(message = "请输入数字---")
    @Range(min = 0, message = "库存不能小于0")
    private Integer stock;
    @TableField(value = "img_path")
    private String imgPath = "暂无";
    @TableLogic
    @TableField(fill = FieldFill.INSERT)
    private Integer deleted;
    @TableField(fill = FieldFill.INSERT)
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private Date createTime;
    @TableField(fill = FieldFill.INSERT_UPDATE)
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private Date updateTime;
    @TableField(fill = FieldFill.INSERT)
    @Version
    private Integer version;

    public Furn(Long id, String name, String maker, double price, Integer sales, Integer stock, String imgPath, Integer deleted, Date createTime, Date updateTime, Integer version) {
        this.id = id;
        this.name = name;
        this.maker = maker;
        this.price = price;
        this.sales = sales;
        this.stock = stock;
        if (StringUtils.hasText(imgPath)) {
            this.imgPath = imgPath;
        }
        this.deleted = deleted;
        this.createTime = createTime;
        this.updateTime = updateTime;
        this.version = version;
    }
}
